package com.huanshi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huanshi.entity.OmsCart;
import com.huanshi.mapper.OmsCartMapper;
import com.huanshi.service.OmsCartService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 幻世
 * @since 2023-10-09
 */
@Service
public class OmsCartServiceImpl extends ServiceImpl<OmsCartMapper, OmsCart> implements OmsCartService {

    @Resource
    OmsCartMapper cartMapper;

    @Override
    public List<OmsCart> getCartListByUserId(Integer userId) {
        LambdaQueryWrapper<OmsCart> queryWrapper = new LambdaQueryWrapper<>();
        if (userId != 0) {
            queryWrapper.eq(OmsCart::getMemberId, userId);
        }
        return cartMapper.selectList(queryWrapper);
    }

    @Override
    public Long checkCart(Integer productId, Integer userId) {
        return cartMapper.selectCount(new LambdaQueryWrapper<OmsCart>().eq(OmsCart::getMemberId, userId).eq(OmsCart::getProductId, productId));
    }
}
